﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MapControl
{
    public partial class Navigator : UserControl
    {
        public event EventHandler ZoomChanged;

        private int zoomLevel = 6;

        public int ZoomLevel
        {
            get { return zoomLevel; }
            set 
            { 
                zoomLevel = value;
                zoomSlider.Value = zoomLevel;
            }
        }

        public Navigator()
        {
            InitializeComponent();
        }

        private void FireZoomChanged()
        {
            if (ZoomChanged != null)
                ZoomChanged(this, EventArgs.Empty);
        }

        private void zoomSlider_ValueChanged(object sender, EventArgs e)
        {
            if (zoomLevel == zoomSlider.Value)
                return;
            zoomLevel = zoomSlider.Value;
            FireZoomChanged();
        }

        private void btnZoomIn_Click(object sender, EventArgs e)
        {
            if (zoomLevel >= zoomSlider.Maximum)
                return;
            zoomLevel++;
            zoomSlider.Value = zoomLevel;
            FireZoomChanged();
        }

        private void btnZoomOut_Click(object sender, EventArgs e)
        {
            if (zoomLevel <= zoomSlider.Minimum)
                return;
            zoomLevel--;
            zoomSlider.Value = zoomLevel;
            FireZoomChanged();
        }

        private void Navigator_Paint(object sender, PaintEventArgs e)
        {

        }

        //protected override void OnPaintBackground(PaintEventArgs e)
        //{
        //    IControlBackground p = Parent as IControlBackground;
        //    e.Graphics.DrawImage(p.BackgroundImage, 0, 0, Bounds, GraphicsUnit.Pixel);
        //}
    }
}
